<?php

/*
 *    This file is part of the module OxProbs for OXID eShop Community Edition.
 *
 *    The module OxProbs for OXID eShop Community Edition is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    The module OxProbs for OXID eShop Community Edition is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with OXID eShop Community Edition.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @link   https://code.google.com/p/oxprobs/
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 * 
 * $Id: oxprobs_articles.php 109 2012-04-22 20:26:35Z jobarthel@gmail.com $
 *
 */
 
class oxprobs_articles extends oxprobs_articles_parent
{
    protected $_sThisTemplate = "oxprobs/oxprobs_articles.tpl";
    public function render()
    {
        parent::render();
        $oSmarty = oxUtilsView::getInstance()->getSmarty();
        $oSmarty->assign( "oViewConf", $this->_aViewData["oViewConf"]);
        $oSmarty->assign( "shop", $this->_aViewData["shop"]);

        $cReportType = isset($_POST['oxprobs_reporttype']) ? $_POST['oxprobs_reporttype'] : $_GET['oxprobs_reporttype']; 
        if (empty($cReportType))
            $cReportType = "nostock";
        $oSmarty->assign( "ReportType", $cReportType );
        
        include "config.inc.php";
        
        switch ($cReportType) {
            case 'nostock':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.oxstock <= 0 '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxstock <= 0 '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'noartnum':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.oxartnum = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxartnum = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'noshortdesc':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.oxshortdesc AS oxshortdesc, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE CHAR_LENGTH(a.oxshortdesc) < '.$this->minDescLen.' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.oxshortdesc AS oxshortdesc, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE CHAR_LENGTH(a.oxshortdesc) < '.$this->minDescLen.' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'noprice':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.oxprice < 0.01 '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxprice < 0.01 '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'noean':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.'.$this->ean.' = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.'.$this->ean.' = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'eanchk':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.'.$this->ean.' != \'\' '
                            . 'AND ('
                                . 'LENGTH(a.'.$this->ean.') != 13 '
                                . 'OR '
                                . 'SUBSTRING((10 - (((('
                                . 'SUBSTRING('.$this->ean.' FROM 2 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 4 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 6 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 8 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 10 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 12 FOR 1)  '
                                . ')*3) + ('
                                . 'SUBSTRING('.$this->ean.' FROM 1 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 3 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 5 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 7 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 9 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 11 FOR 1)'
                                . ')) MOD 10)) FROM -1 FOR 1) != SUBSTRING('.$this->ean.' FROM 13 FOR 1) '
                                . ') '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.'.$this->ean.' != \'\' '
                            . 'AND ('
                                . 'LENGTH(a.'.$this->ean.') != 13 '
                                . 'OR '
                                . 'SUBSTRING((10 - (((('
                                . 'SUBSTRING('.$this->ean.' FROM 2 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 4 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 6 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 8 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 10 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 12 FOR 1)  '
                                . ')*3) + ('
                                . 'SUBSTRING('.$this->ean.' FROM 1 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 3 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 5 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 7 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 9 FOR 1) + '
                                . 'SUBSTRING('.$this->ean.' FROM 11 FOR 1)'
                                . ')) MOD 10)) FROM -1 FOR 1) != SUBSTRING('.$this->ean.' FROM 13 FOR 1) '
                                . ') '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'nompn':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.oxmpn = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxvarcount = 0 '
                            . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                        . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxmpn = \'\' '
                            . 'AND a.oxactive = 1 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                break;

            case 'nocat':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, m.oxtitle AS oxmantitle '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE NOT EXISTS ( '
                            . 'SELECT * '
                            . 'FROM oxobject2category o2c '
                            . 'WHERE a.oxid = o2c.oxobjectid '
                            . ') '
                        . 'AND a.oxactive = 1 '
                        . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSQL2 = '';
                break;

            case 'orphan':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxparentid AS oxparentid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmnp, '
                        . '( '
                            . 'SELECT b.oxtitle '
                            . 'FROM oxarticles b '
                            . 'WHERE a.oxparentid = b.oxid '
                            . ') AS oxtitle, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                            . ') AS oxmantitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxactive = 1 '
                            . 'AND ('
                                . 'SELECT b.oxactive '
                                . 'FROM oxarticles b '
                                . 'WHERE a.oxparentid = b.oxid '
                                . ') = 0 '
                            . 'AND a.oxstockflag = 1 '
                            . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY oxtitle ';
                $sSQL2 = '';
                break;

            case 'nodesc':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, e.oxlongdesc, '
                        . '( '
                            . 'SELECT m.oxtitle '
                            . 'FROM oxmanufacturers m '
                            . 'WHERE a.oxmanufacturerid = m.oxid '
                        . ') AS oxmantitle '
                        . 'FROM oxarticles a, oxartextends e  '
                        . 'WHERE a.oxid = e.oxid '
                        . 'AND TRIM(e.oxlongdesc) = \'\' '
                        . 'AND a.oxactive = 1 '
                        . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, '
                        . '(SELECT b.oxtitle FROM oxarticles b WHERE a.oxparentid = b.oxid) AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, e.oxlongdesc, '
                        . '('
                            .'SELECT m.oxtitle '
                            . 'FROM oxarticles c '
                            . 'LEFT JOIN oxmanufacturers m ON c.oxmanufacturerid = m.oxid '
                            . 'WHERE a.oxparentid = c.oxid '
                        . ') AS oxmantitle '
                        . 'FROM oxarticles a, oxartextends e '
                        . 'WHERE a.oxid = e.oxid '
                        . 'AND TRIM(e.oxlongdesc) = \'\' '
                        . 'AND (SELECT TRIM(f.oxlongdesc) FROM oxarticles b, oxartextends f WHERE b.oxid = f.oxid AND b.oxid = a.oxparentid) = \'\' '
                        . 'AND a.oxactive = 1 '
                        . 'AND a.oxparentid != \'\' '
                        . 'ORDER BY a.oxtitle ';
                break;

            case 'nomanu':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, a.oxmanufacturerid  '
                        . 'FROM oxarticles a '
                        . 'WHERE a.oxmanufacturerid = \'\' '
                        . 'AND oxactive = 1 '
                        . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = '';
                break;

            case 'novend':
                $sSql1 = 'SELECT a.oxid AS oxid, a.oxartnum AS oxartnum, a.'.$this->ean.' AS oxean, a.oxmpn AS oxmpn, a.oxtitle AS oxtitle, '
                        . 'a.oxvarselect AS oxvarselect, a.oxstock AS oxstock, a.oxprice AS oxprice, a.oxmanufacturerid, m.oxtitle AS oxmantitle  '
                        . 'FROM oxarticles a '
                        . 'LEFT JOIN oxmanufacturers m ON a.oxmanufacturerid = m.oxid '
                        . 'WHERE a.oxvendorid = \'\' '
                        . 'AND a.oxactive = 1 '
                        . 'AND a.oxparentid = \'\' '
                        . 'ORDER BY a.oxtitle ';
                $sSql2 = '';
                break;
            
            default:
                $sSql = '';
                break;
        }

        $i = 0;
        $aArticles = array();

        if (!empty($sSql1)) {
            $rs = oxDb::getDb(true)->Execute($sSql1);
            /*echo '<pre>';
            echo $sSql1;
            echo '</pre>';
            echo '<pre>';
            echo $sSql2;
            echo '</pre>';*/
            while (!$rs->EOF) {
                array_push($aArticles, $rs->fields);
                $rs->MoveNext();
            }
        }
        
        if (!empty($sSql2)) {
            $rs = oxDb::getDb(true)->Execute( $sSql2);
            while (!$rs->EOF) {
                array_push($aArticles, $rs->fields);
                $rs->MoveNext();
            }
        }

         $oSmarty->assign("aArticles",$aArticles);

         return $this->_sThisTemplate;
   }
 }
?>